<?php echo $this->render('/public/header');?>
<?php use yii\helpers\Url;?>
<div id="main" class="col-xs-12">
    <div class="layui-box layui-upload-button"><form target="layui-upload-iframe" method="post" key="set-mine" enctype="multipart/form-data" action=""><input type="file" name="file" id="file" lay-type="file" lay-title="快递单据批量上传" class="layui-upload-file"></form><span class="layui-upload-icon"><i class="layui-icon"></i>快递单据批量上传</span></div>
    <div style="margin-left: 10px;display: inline-block;">
        <div class="layui-box layui-upload-button"><form target="layui-upload-iframe" method="post" key="set-mine" enctype="multipart/form-data" action=""><input type="file" name="repo" id="repo" lay-type="file" lay-title="仓库单据批量上传" class="layui-upload-file"></form><span class="layui-upload-icon"><i class="layui-icon"></i>仓库单据批量上传</span></div>
    </div>
    <div style="margin-left: 10px;display: inline-block;">
        <div class="layui-box layui-upload-button"><form target="layui-upload-iframe" method="post" key="set-mine" enctype="multipart/form-data" action=""><input type="file" name="print" id="print" lay-type="file" lay-title="印刷单据批量上传" class="layui-upload-file"></form><span class="layui-upload-icon"><i class="layui-icon"></i>印刷单据批量上传</span></div>
    </div>

    <br>
    <br>
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">快递单据添加</li>
            <li class="">仓库单据添加</li>
            <li class="">打印费用添加</li>
        </ul>
    </div>
    <div id="tabcontent">
        <div>
            <div id="tab1" style="height:400px"></div>
            <button class="layui-btn layui-btn-normal" onclick="express_upload()">提交快递单据</button>
        </div>
        <div >
            <div id="tab2" style="height:400px"></div>
            <button class="layui-btn layui-btn-normal" onclick="upload_repo()">提交仓库单据</button>
        </div>
        <div>
            <div id="tab3" style="height:400px" ></div>
            <button class="layui-btn layui-btn-normal" onclick="upload_print()">提交打印费单据</button>
        </div>
    </div>
</div>
<script>
var data = [
    ['', '', '', '', '', '','','','','','',''],
    ['', '', '', '', '', '','','','','','',''],
    ['', '', '', '', '', '','','','','','',''],
    ['', '', '', '', '', '','','','','','',''],
    ['', '', '', '', '', '','','','','','','']
],
container = document.getElementById('tab1');

hot = new Handsontable(container, {
data: data,
    height:"400px",
    minSpareRows: 1,
    colHeaders:[
        '日期','快递公司','业务员','客户编号','客户名称','invoice',
        '国家','发件渠道','快递单号','转单号','数量','总量',
        '单价','费用','备注'
    ],
    dropdownMenu: true,
    contextMenu: true,
    stretchH: 'all',
    columns: [
{

    type: 'date',
        dateFormat: 'YYYY-MM-DD',
        correctFormat: true,
defaultDate: (new Date().getYear())
},
{
    editor: 'select',
        selectOptions:<?php echo $this->params['express_list'];?>
},
{
    editor: 'select',
        selectOptions:<?php echo $this->params['staff_list'];?>

},
{
    //data:"remain_money"
},
{
    //data:"country"
},
{
    //data:"number"
},
{
    //data:"customer_name"
},
{

},
{
    //data:"type"
},
{
    //data:"product"
},
{
    //data:"account"
},
{
    //data:"buyer"
},
{
    //data:"invoice_num"
},
{
}
,{}
]

});
</script>
<script>
var data2 = [
    ['', '', '', '', '', '','','','','','','',''],
    ['', '', '', '', '', '','','','','','','',''],
    ['', '', '', '', '', '','','','','','','',''],
    ['', '', '', '', '', '','','','','','','',''],
    ['', '', '', '', '', '','','','','','','','']
],
container = document.getElementById('tab2');

hot = new Handsontable(container, {
data: data2,
    height:"400px",
    minSpareRows: 1,
    colHeaders:[
        '日期','业务员','产品','数量','包装','纸箱',
        '提付','运费','合计','客户编号','客户全名','invoice','备注'
    ],
    dropdownMenu: true,
    contextMenu: true,
    stretchH: 'all',
    columns: [
{

    type: 'date',
        dateFormat: 'YYYY-MM-DD',
        correctFormat: true,
defaultDate: (new Date().getYear())
},
{
    editor: 'select',
        selectOptions:<?php echo $this->params['staff_list'];?>
},
{


},
{
    //data:"remain_money"
},
{
    //data:"country"
},
{
    //data:"number"
},
{
    //data:"customer_name"
},
{

},
{
    //data:"type"
},
{
    //data:"product"
},
{
    //data:"account"
},
{
    //data:"buyer"
},
{
    //data:"invoice_num"
}
]

});
</script>
<script>
var data3 = [
    ['', '', '', '', '', '','','',''],
    ['', '', '', '', '', '','','',''],
    ['', '', '', '', '', '','','',''],
    ['', '', '', '', '', '','','',''],
    ['', '', '', '', '', '','','','']
],
container = document.getElementById('tab3');

hot = new Handsontable(container, {
data: data3,
    height:"400px",
    minSpareRows: 1,
    colHeaders:[
        '日期','产品名称','数量','单价','业务员','费用','invoice','备注','group'
    ],
    dropdownMenu: true,
    contextMenu: true,
    stretchH: 'all',
    columns: [
{

    type: 'date',
        dateFormat: 'YYYY-MM-DD',
        correctFormat: true,
defaultDate: (new Date().getYear())
},
{

},
{


},
{
    //data:"remain_money"
},
{
    editor: 'select',
        selectOptions:<?php echo $this->params['staff_list'];?>
},
{
    //data:"number"
},
{
    //data:"customer_name"
},
{

},
{
    //data:"type"
}
]

});
</script>
<script>
var layer = layui.layer;
layui.upload({
url: '<?php echo Url::to(['finance/upload_express_excel']);?>',
    elem: '#file' ,
    method: 'post' ,
    before: function(input){
        layer.load(1, {
        shade: [0.1,'#fff'] 
    });
    },
    success: function(res){
        layer.closeAll('loading');
        if(res.code!=1)
        {
            layer.alert(res.msg);
        }
        else
        {
            layer.alert('添加成功');
        }
    }
});
layui.upload({
url: '<?php echo Url::to(['finance/upload_repo_fee_excel']);?>',
    elem: '#repo' ,
    method: 'post' ,
    before: function(input){
        layer.load(1, {
        shade: [0.1,'#fff'] 
    });
    },
    success: function(res){
        layer.closeAll('loading');
        if(res.code!=1)
        {
            layer.alert(res.msg);
        }
        else
        {
            layer.alert('添加成功');
        }
    }
});
layui.upload({
url: '<?php echo Url::to(['finance/print_upload_excel']);?>',
    elem: '#print' ,
    method: 'post' ,
    before: function(input){
        layer.load(1, {
        shade: [0.1,'#fff'] 
    });
    },
    success: function(res){
        layer.closeAll('loading');
        if(res.code!=1)
        {
            layer.alert(res.msg);
        }
        else
        {
            layer.alert('添加成功');
        }
    }
});

var tab = layui.element();
tab.on('tab',function(data){
    $("#tabcontent").children('div').each(function(){
        if($(this).index()==data.index)
        {
            $(this).css('display','block');

        }
        else
        {
            $(this).hide();
        }
    })
})
    function express_upload()
    {
        if(layer.confirm('确认上传',{},function(){
            if(!data[0][0])
            {
                layer.alert("无数据");return false;
            }
            var url = "<?php echo Url::to(['finance/express_add']);?>";
            $.post(url,{data:data},function(res){
                if(res.code==1)
                {
                    layer.confirm(res.msg,{},function(){
                        window.location.reload();
                    })
                }
                else
                {
                    layer.alert(res.msg);
                }
            },'json')
        }));
    }

function upload_repo()
{
    if(layer.confirm('确认上传',{},function(){
        if(!data2[0][0])
        {
            layer.alert("无数据");return false;
        }
        var url = "<?php echo Url::to(['finance/repo_add']);?>";
        $.post(url,{data:data2},function(res){
            if(res.code==1)
            {
                layer.confirm(res.msg,{},function(){
                    window.location.reload();
                })
            }
            else
            {
                layer.alert(res.msg);
            }
        },'json')
    }));
}

function upload_print()
{
    if(layer.confirm('确认上传',{},function(){
        if(!data3[0][0])
        {
            layer.alert("无数据");return false;
        }
        var url = "<?php echo Url::to(['finance/print_add']);?>";
        $.post(url,{data:data3},function(res){
            if(res.code==1)
            {
                layer.confirm(res.msg,{},function(){
                    window.location.reload();
                })
            }
            else
            {
                layer.alert(res.msg);
            }
        },'json')
    }));
}
</script>
<?php echo $this->render('/public/footer');?>
